//============================================================================
// Name        : ms008.cpp
// Author      : Tadas
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include "lib.h"
using namespace std;

int main()
{
	int i, k;
	int n = 4;
	double **mas, **at, *b, *x, *bt, ats;

	mas = allocate2d(n, n);
	at = allocate2d(n, n);
	b = allocate1d(n);
	bt = allocate1d(n);
	x = allocate1d(n);

	mas[0][0] = 1; mas[0][1] = 5; mas[0][2] = 2; mas[0][3] =4;
	mas[1][0] = 4; mas[1][1] = 1; mas[1][2] = 3; mas[1][3] =1;
	mas[2][0] = 2; mas[2][1] = 2; mas[2][2] = 1; mas[2][3] =4;
	mas[3][0] = 3; mas[3][1] = 2; mas[3][2] = 1; mas[3][3] =5;
	b[0] = 1; b[1] = 6; b[2] = 2; b[3] = 4;

	for (i=0; i<n; i++)
	{
		for (k=0; k<n; k++) at[i][k]=mas[i][k];
		bt[i]=b[i];
	}

	lowup(mas, n);
	solve(mas, b, x, n);

	for (i=0; i<n; i++)
	{
		ats = 0;
		for (k=0; k<n; k++) ats += at[i][k]*x[k];
		printf("%f\t%f\t%f\n",x[i], ats, bt[i]);
	}


	return 0;
}
